package com.nuo.admin.api;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
import com.nuo.admin.base.entity.SysOauthClient;
import com.nuo.admin.base.service.ISysOauthClientService;
import com.nuo.admin.pojo.dto.AuthClientDTO;
import com.nuo.common.core.constant.DubboConstant;
import com.nuo.common.core.result.Result;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;

/**
 * @author LGC
 * @date 2022/2/9 14:50
 */
@Slf4j
@AllArgsConstructor
@DubboService(version = DubboConstant.VERSION_1, retries = DubboConstant.RETRIES, timeout = DubboConstant.TIMEOUT)
public class OAuthClientProviderImpl implements OAuthClientProvider {

    private final ISysOauthClientService iSysOauthClientService;

    @Override
    public Result<AuthClientDTO> getOAuth2ClientById(String clientId) {
        log.info("根据clientId获取客户端");
        SysOauthClient client = iSysOauthClientService.getById(clientId);
        Assert.isTrue(client != null, "OAuth2 客户端不存在");
        AuthClientDTO authClientDTO = new AuthClientDTO();
        BeanUtil.copyProperties(client, authClientDTO);
        return Result.success(authClientDTO);
    }
}
